package org.ecpkn.PAGridSim.core.tasksCreation;


import gridsim.Gridlet;

/**
 * @author Lin Zhou
 * 
 *         Module:Jobs Creation
 * 			Job类是一个工作集，继承自Gridlet类，属于某个Task
 */
public class Job extends Gridlet {
	

	// 到达时间
	private double arriveTime_;
	// 所属的任务（Task）
	private Task task_;

	/**
	 * Constructor of the class Job
	 * 
	 * @param jobID
	 *            jobId consists of its taskId and the repeatNumber
	 * 
	 * @param task
	 *            the parent task that this job belongs to
	 * @param repeatNumber
	 * 
	 */
	public Job(int jobID, Task task, int repeatNumber) {
		// filesize=0,fileOutputSize=0,in order to prevent the influence of
		// communication delay. record=true
		super(jobID, task.getLength_(), 0, 0, true);
		this.task_ = task;
		// the arriveTime depends on the submitted time of the task and
		// the repeatNumber of the job
		this.arriveTime_ = calculateArriveTime(repeatNumber);
	}

	/**
	 * 计算到达时间
	 * arriveTime=repeatNumber * this.task_.getPeriod_() + this.task_.getSubmitedTime_()
	 * 到达时间 = 重复次数 * 任务周期 + 提交时间
	 * 
	 * @param repeatNumber
	 * @return job arriveTime
	 */
	private double calculateArriveTime(int repeatNumber) {
		return repeatNumber * this.task_.getPeriod_()
				+ this.task_.getSubmitedTime_();
	}

	public double getPeriode_() {
		return this.task_.getPeriod_();
	}

	/**
	 * 计算截止时间
	 * deadline= this.arriveTime_ + this.task_.getPeriod_();
	 * 截止时间 = 到达时间 + 任务周期
	 * @return job deadline
	 */
	public double getDeadline_() {
		return this.arriveTime_ + this.task_.getPeriod_();
	}
	// 获得任务到达时间
	public double getArriveTime_() {
		return arriveTime_;
	}
	// 获得任务ID
	public int getTaskID_() {
		return this.task_.getTaskID_();
	}

	public Task getTask_() {
		return task_;
	}
}
